<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?  
    set_time_limit(24*86400);
    ini_set('memory_limit', '256M');
    require_once ('inc_config.php');
    ob_clean();
    $curl = new Curl_HTTP_Client();
    $souce = getValue('souce_link','int','POST',0);
    $db_law = new db_query("SELECT * 
                            FROM laws
                            WHERE law_active = 1");
    $law = $db_law->resultArray();
    unset($db_law);
    $total = count($law);
    $count = getValue('c','int','GET',0);
    while ($count < $total) {
        $links          = $law[$count]['law_link'];
        $law_id         = $law[$count]['law_id'];
        $domain         = $law[$count]['law_dom_id'];
        $cond_type      = $law[$count]['law_link_details'];
        $html           = $curl->fetch_url($links);
        $html           = str_get_html($html);
        foreach($html->find($cond_type) as $contents){
            $link_details       = $contents->href;
            $link_details       = check_domain($domain,$link_details);
            if($link_details != ''){
                $link_details_md5 = md5($link_details);
                $errorMsg = "";
                $myform  = new generate_form();
                $myform->removeHTML(0);
                $myform->addTable('links') ;
                $myform->add('lin_law_id','law_id',0,1,0,0,'');
                $myform->add('lin_value','link_details',0,1,'',0);
                $myform->add('lin_value_md5','link_details_md5',0,1,'',0,'',1,'Trùng tiêu đề');
                $errorMsg .= $myform->checkdata();
                if($errorMsg==""){
                    $db_insert = new db_execute_return();
                    @$last_id = $db_insert->db_execute($myform->generate_insert_SQL());  
                    echo 'Lấy thành công tin:  <a>'. $link_details,'</a></br>'; 
                    unset($db_insert);
                }
            }
        }
        if(!@$last_id){
            echo 'Hết link để lấy';
        }
        $count++;
        sleep(5);
        redirect('get_link_details.php?c='.$count);
    }
    unset($curl);
    if($count >= $total){
        redirect('get_link_details.php');
    }
?>
